package com.ruoyi.project.module.guanli.controller;

import java.util.List;

import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.guanli.domain.Guanli;
import com.ruoyi.project.module.guanli.service.IGuanliService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 旅客 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-12
 */
@Controller
@RequestMapping("/module/guanli")
public class GuanliController extends BaseController
{
    private String prefix = "module/guanli";
	
	@Autowired
	private IGuanliService guanliService;
	
	@RequiresPermissions("module:guanli:view")
	@GetMapping()
	public String guanli()
	{
	    return prefix + "/guanli";
	}
	
	/**
	 * 查询旅客列表
	 */
	@RequiresPermissions("module:guanli:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Guanli guanli)
	{
		startPage();
        List<Guanli> list = guanliService.selectGuanliList(guanli);
		return getDataTable(list);
	}
	/**
	 * 导出旅客
	 */
	@Log(title = "旅客", businessType = BusinessType.EXPORT)
	@RequiresPermissions("system:guanli:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(Guanli guanli) throws Exception
	{
		try
		{
			List<Guanli> list = guanliService.selectGuanliList(guanli);
			ExcelUtil<Guanli> util = new ExcelUtil<Guanli>(Guanli.class);
			return util.exportExcel(list, "guanli");
		}
		catch (Exception e)
		{
			return error("导出Excel失败，请联系网站管理员！");
		}
	}
	
	/**
	 * 新增旅客
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存旅客
	 */
	@RequiresPermissions("module:guanli:add")
	@Log(title = "旅客", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Guanli guanli)
	{		
		return toAjax(guanliService.insertGuanli(guanli));
	}

	/**
	 * 修改旅客
	 */
	@GetMapping("/edit/{userId}")
	public String edit(@PathVariable("userId") Integer userId, ModelMap mmap)
	{
		Guanli guanli = guanliService.selectGuanliById(userId);
		mmap.put("guanli", guanli);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存旅客
	 */
	@RequiresPermissions("module:guanli:edit")
	@Log(title = "旅客", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Guanli guanli)
	{		
		return toAjax(guanliService.updateGuanli(guanli));
	}
	
	/**
	 * 删除旅客
	 */
	@RequiresPermissions("module:guanli:remove")
	@Log(title = "旅客", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(guanliService.deleteGuanliByIds(ids));
	}
	
}
